/*
自己选择的路 ,跪着也要走完。朋友们 , 虽然这个世界日益浮躁起来,只
要能够为了当时纯粹的梦想和感动坚持努力下去 , 不管其它人怎么样,我
们也能够保持自己的本色走下去。
To the world , you will be a person , but to a person , you
will be the world .                               ——AKPower
*/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
// ll *****dp;
// ll dp[35][35][35][35][35];
// vector<ll> dp[35][35][35][35];
ll k, a[6], cnt[6];

int main()
{
    IOS;
    while (cin >> k && k)
    {
        memset(cnt, 0, sizeof(cnt));
        ll n = 0;
        memset(a,0,sizeof(a));
        for (ll i = 0; i < k; i++)
        {
            cin >> a[i];
        }
        ll dp[a[0]+2][a[1]+2][a[2]+2][a[3]+2][a[4]+2];
        memset(dp, 0, sizeof(dp));
        dp[0][0][0][0][0] = 1;
        for (ll a0 = 0; a0 <= a[0]; a0++)
        {
            for (ll a1 = 0; a1 <= a[1]; a1++)
            {
                if(a0<a[0]&&a0<a1)break;
                for (ll a2 = 0; a2 <= a[2]; a2++)
                {
                    if(a1<a[1]&&a1<a2)break;
                    for (ll a3 = 0; a3 <= a[3]; a3++)
                    {
                        if(a2<a[2]&&a2<a3)break;
                        for (ll a4 = 0; a4 <= a[4]; a4++)
                        {
                            if(a3<a[3]&&a3<a4)break;
                            dp[a0+1][a1][a2][a3][a4]+=dp[a0][a1][a2][a3][a4];
                            dp[a0][a1+1][a2][a3][a4]+=dp[a0][a1][a2][a3][a4];
                            dp[a0][a1][a2+1][a3][a4]+=dp[a0][a1][a2][a3][a4];
                            dp[a0][a1][a2][a3+1][a4]+=dp[a0][a1][a2][a3][a4];
                            dp[a0][a1][a2][a3][a4+1]+=dp[a0][a1][a2][a3][a4];
                        }
                    }
                }
            }
        }
        cout << dp[a[0]][a[1]][a[2]][a[3]][a[4]] << endl;
    }

    getchar();
    getchar();
    return 0;
}
